#include "main.h"

int main(){

    //创立连接
    int socketFD;
    socket_link(&socketFD, "192.168.40.128", "8080");


    //登录和注册
    judge_login(socketFD);

    client_t *cl;
    cl = (client_t *)malloc(1* sizeof(client_t));
    while(1){
        bzero(cl, sizeof(client_t));
        int ret = recv(socketFD, cl, sizeof(client_t), MSG_WAITALL);
        ERROR_CHECK(ret, -1, "recv_main.c");
        printf("%s:%s$ ", cl->name, cl->dir_path);
        fflush(stdout);

        char buf[120] = { 0 };
        ret = read(STDIN_FILENO, buf, sizeof(buf));
        ERROR_CHECK(ret, -1, "read_main.c");

        sendc_t *sc = (sendc_t *)malloc(1*sizeof(sendc_t));
        bzero(sc, sizeof(sendc_t));
        slice_command(buf, sc);
        if(sc->num == 3){
            printf("%s\n", cl->dir_path);
            printf("%s:%s$ ", cl->name, cl->dir_path);
            fflush(stdout);

            char buf[120] = { 0 };
            ret = read(STDIN_FILENO, buf, sizeof(buf));
            ERROR_CHECK(ret, -1, "read_main.c");

            bzero(sc, sizeof(sendc_t));
            slice_command(buf, sc);

        }
        ret = send(socketFD, sc, sizeof(sendc_t), MSG_NOSIGNAL);
        ERROR_CHECK(ret, -1, "send_main");
        if(sc->num == 8){
            free(sc);
            break;
        }

        //接收服务端发送来的信息
        recv_msg(socketFD, sc);
        free(sc);

    }

    printf("欢迎下次使用\n");

    free(cl);

    close(socketFD);

    return 0;
}

